﻿using System;
using System.Data;
using Besture.Common;
using Besture.Dal;
using Besture.Dal.UserBase;
using Besture.Model;
using Besture.Model.XiangSheng;

namespace Besture.Bll.UserBase
{ 
    public partial class PointsRecordDac : BaseFacade
    {
        //private readonly PointsRecordDal excuteDal = new PointsRecordDal();

        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="model">数据模型</param>
        /// <returns></returns>
        public int Add(PointsRecordModel model)
        {
            try
            {
                base.CreateConnection(); 
                base.BeginTransaction();
                PointsRecordDal excuteDal = new PointsRecordDal();
                int lsRecord = 0;
                lsRecord = excuteDal.Add(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">数据模型</param>
        /// <returns></returns>
        public int Update(PointsRecordModel model) 
        {
            try
            {
                base.CreateConnection();
                base.BeginTransaction();
                PointsRecordDal excuteDal = new PointsRecordDal();
                int lsRecord = 0;
                lsRecord = excuteDal.Update(model);
                if (lsRecord > 0)
                {
                    base.Commit();
                    return lsRecord;
                }
                else
                {
                    base.RollBack();
                    return -1;
                }
            }
            catch (Exception e)
            {
                base.RollBack();
                throw e;
            }
            finally
            {
                base.CloseConnection();
            }
        }


        
        /// <summary>
        /// 获取数据模型
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
       public PointsRecordModel GetModel(int id)
        {
            try
            {
                base.CreateConnection();
                PointsRecordDal excuteDal = new PointsRecordDal();
                return excuteDal.GetModel(id);
            }
            catch (Exception e)
            {
                throw e;
            }
           finally
            {
                 CloseConnection();
            }
        }

        /// <summary>
       /// 获取全部数据
       /// </summary>
       /// <returns></returns>
       public DataTable GetDataTableByUserId(int iUserId)
        {
            try
            {
                base.CreateConnection();
                PointsRecordDal excuteDal = new PointsRecordDal();
                return excuteDal.GetDataTableByUserId(iUserId);
            }
            catch (Exception e)
            {
                throw e;
            }
           finally
            {
               CloseConnection();
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        public int Delete(int id)
        {
            try
            {
                base.CreateConnection();
                PointsRecordDal excuteDal = new PointsRecordDal();
                return excuteDal.Delete(id);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
               CloseConnection();
            }
        }

        
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="idList">主键值集合</param>
        /// <returns></returns>
        public int DeleteList(string ids)
        {
            try
            {
                base.CreateConnection();
                PointsRecordDal excuteDal = new PointsRecordDal();
                return  excuteDal.DeleteList(ids);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
              CloseConnection();
            }
        }
    }
}

